package com.hue.gulimail.gulimailproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hue.gulimail.gulimailproduct.entity.SkuInfoEntity;
import com.hue.gulimail.gulimailproduct.service.SkuInfoService;
import com.hue.common.utils.PageUtils;
import com.hue.common.utils.R;


/**
 * sku信息
 *
 * @author yaofengqiao
 * @email 451737523@qq.com
 * @date 2021-08-12 16:24:48
 */
@RestController
@RequestMapping("gulimailproduct/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping("/getAll")
    public R getAll() {
        List<SkuInfoEntity> skuInfos = skuInfoService.list();
        return R.ok().put("data", skuInfos);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("gulimailproduct:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
//        PageUtils page = skuInfoService.queryPage(params);
        PageUtils page = skuInfoService.querySkuInfoPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    //@RequiresPermissions("gulimailproduct:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("gulimailproduct:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gulimailproduct:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gulimailproduct:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds) {
        skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

    /**
     * 根据sku_id获取一个SkuInfo
     */
    @GetMapping("/getBySkuId/{skuId}")
    public R getBySkuId(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo);
    }
}
